From 9fa6e8fb60dd467e27b075c04d46204ce87a83ce Mon Sep 17 00:00:00 2001 From: Joseph Marrero Corchado Date: Thu, 29 May 2025 14:48:50 -0400 Subject: [PATCH] ostree-prepare-root: add option processing for kernel arguments In a future soft-reboot feature this will allow us to pass kernel arguments for the deployment we are going to soft-reboot into. --- src/switchroot/ostree-prepare-root.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index 68707f10..1e77809f 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -97,6 +97,8 @@ #include "ostree-mount-util.h" +static GOptionEntry options[] = { { NULL } }; + static bool sysroot_is_configured_ro (const char *sysroot) { @@ -261,11 +263,26 @@ main (int argc, char *argv[]) struct stat stbuf; g_autoptr (GError) error = NULL; + g_autoptr (GOptionContext) context = g_option_context_new ("SYSROOT [KERNEL_CMDLINE]"); + g_option_context_add_main_entries (context, options, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)) + errx (EXIT_FAILURE, "Error parsing options: %s", error->message); + if (argc < 2) - err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT"); + err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT [KERNEL_CMDLINE]"); const char *root_arg = argv[1]; - g_autofree char *kernel_cmdline = read_proc_cmdline (); + g_autofree char *kernel_cmdline = NULL; + if (argc < 3) + { + kernel_cmdline = read_proc_cmdline (); + } + else + { + // Duplicate argv[2] so g_autofree can safely manage it. + kernel_cmdline = g_strdup (argv[2]); + } + if (!kernel_cmdline) errx (EXIT_FAILURE, "Failed to read kernel cmdline"); -- 2.30.2